#include<bits/stdc++.h>
using namespace std;
int T,n,ans;
struct
{
	int a;
	int b;
}a[200005];
int ci(int x)
{
	for(int i=x-1;i>=0;i--)
	{
		if(a[x].b==a[i].b)
		{
			if(a[x].a==a[i].a)return a[i].a;
			else return 0;
		}
	}
	return 0;
}
int su()
{
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		cnt+=ci(i);
	}
	return cnt;
}
void bfs(int x)
{
	a[x].b=1;
	ans=max(ans,su());
	if(x<n)bfs(x+1);
	a[x].b=0;
	if(x<n)bfs(x+1);
}
int main()
{
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	cin>>T;
	while(T--)
	{
		memset(a,0,sizeof a);
		cin>>n;
		for(int i=0;i<n;i++)
		{
			cin>>a[i].a;
		}
		ans=su();
		bfs(1);
		cout<<ans<<endl;
	}
	return 0;
}
